<template>
 <div class="header-container">
   <div class="logo-container">
     <img :src="imgUrl" class="logo-icon">
     <span class="logo-text">图书馆管理系统</span>
   </div>
   <div class="spacer"></div>
   <div class="user-container">
     <el-dropdown>
      <span class="user-dropdown-link">
        {{user.nickName}} <i class="el-icon-arrow-down"></i>
      </span>
       <template #dropdown>
         <el-dropdown-menu>
           <el-dropdown-item @click="exit">退出系统</el-dropdown-item>
         </el-dropdown-menu>
       </template>
     </el-dropdown>
   </div>
 </div>
</template>

<script>
import {ElMessage} from "element-plus";

export default {
  name: "Header",
  props: ['user'],
  data(){
    return{
      user:[],
      imgUrl:require("../assets/icon/login.png")
    }
  },
  created(){
    let userStr = sessionStorage.getItem("user")||"{}"
    this.user = JSON.parse(userStr)
  },
  methods:{
    exit(){
      sessionStorage.removeItem("user")
      this.$router.push("/login")
      ElMessage.success("退出系统成功")
    }
  }

}
</script>

<style scoped>
.header-container {
  height: 60px;
  line-height: 60px;
  background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  padding: 0 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.logo-container {
  display: flex;
  align-items: center;
  width: 200px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}

.logo-text {
  font-size: 18px;
  font-weight: bold;
  white-space: nowrap;
}

.spacer {
  flex: 1;
}

.user-container {
  min-width: 120px;
  display: flex;
  justify-content: flex-end;
}

.user-dropdown-link {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: white;
  font-weight: 500;
}
</style>